from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
import time
import pandas as pd
from lxml import etree
list = []
s = Service('./chromedriver.exe')
web = webdriver.Chrome(service=s)
web.get(f'https://www.zhipin.com/web/geek/job?query=前端开发工程师&city=101191100&page=1')
while True:
    ab = input(':')
    if ab == 'a':
        print(1)
        html1 = web.page_source
        etree1 = etree.HTML(html1)
        xpath1 = etree1.xpath('//*[@id="container"]/div[2]/div/div[3]/div[2]/ul/li')
        for i in xpath1:
            
            ming = i.xpath('./a/div[1]/div[1]/h3/a/div[1]/span[1]/text()')
            weizhi = i.xpath('./a/div[1]/div[1]/h3/a/div[1]/span[2]/span/span/text()')
            xinzi = i.xpath('./a/div[1]/div[1]/div/span/text()')
            qiye = i.xpath('./a/div[1]/div[2]/div/h3/a')
            url = i.xpath('./a/@href')

            list.append([ming, weizhi, xinzi, qiye, url])
            print([ming, weizhi, xinzi, qiye, url])
    else:
        print(2)
        excle = pd.DataFrame(list, columns=['岗位名称', '位置', '薪资', '企业名称', '链接'])
        excle.to_csv('./boss.csv')
        break
    print(list)
    web.find_element(By.XPATH, '//*[@id="container"]/div[2]/div/div[3]/div[3]/div/div/a[last()]').click()